<?php
/*
 * @Author: sunkaiyuan sunkaiyuan@namenode.com
 * @Date: 2022-10-10 15:16:06
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-07-25 16:39:01
 * @Description: 
 */

namespace App\Providers;

use App\Models\Api;
use App\Models\Config;
use App\Models\TemporaryToken;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
    {
    /**
     * Register any application services.
     *
     * @return void
     */
    public function boot()
        {
        $this->app['token'] = function ()
            {
            $request = request();
            $token = "";
            if ($request->has('temporaryToken')) {
                $token = $request->input('temporaryToken');
                }
            else {
                $token = $request->header('Authorization');
                }
            return TemporaryToken::whereApiToken($token)->first();

            };

        $this->app['api'] = function ()
            {
            return Api::FirstOrCreate(getRouter());
            };
        $this->app['sys'] = Config::first();
        }
    public function register()
        {
        //
        }
    }